home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Mark Pilgrim / Lose Your Marbles! 1.0 / source / ls code ƒ / ls meat.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-30  |  2.9 KB  |  129 lines  |  [TEXT/KAHL]

  1. /**********************************************************************\
  2.  
  3. File:        ls meat.c
  4.  
  5. Purpose:    This module handles all the blood and guts of Lose Your Marbles!
  6.             play: what constitutes a valid move, etc.
  7.  
  8. This program is free software; you can redistribute it and/or modify
  9. it under the terms of the GNU General Public License as published by
  10. the Free Software Foundation; either version 2 of the License, or
  11. (at your option) any later version.
  12.  
  13. This program is distributed in the hope that it will be useful,
  14. but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16. GNU General Public License for more details.
  17.  
  18. You should have received a copy of the GNU General Public License
  19. along with this program in a file named "GNU General Public License".
  20. If not, write to the Free Software Foundation, 675 Mass Ave,
  21. Cambridge, MA 02139, USA.
  22.  
  23. \**********************************************************************/
  24.  
  25. #include "ls meat.h"
  26. #include "environment.h"
  27. #include "program globals.h"
  28.  
  29. Boolean DeleteOneMove(Point theMove)
  30. {
  31.     short            i, j;
  32.     
  33.     for (i=0; i<gNumMoves; i++)
  34.     {
  35.         if ((gMoves[i].h==theMove.h) && (gMoves[i].v==theMove.v))
  36.         {
  37.             for (j=i; j<gNumMoves-1; j++)
  38.             {
  39.                 gMoves[j].h=gMoves[j+1].h;
  40.                 gMoves[j].v=gMoves[j+1].v;
  41.             }
  42.             
  43.             gNumMoves--;
  44.             
  45.             return TRUE;
  46.         }
  47.     }
  48.     
  49.     return FALSE;
  50. }
  51.  
  52. Boolean AddOneMove(Point theMove)
  53. {
  54.     if (gNumMoves==gNumRows*gNumColumns)
  55.         return FALSE;
  56.     
  57.     gMoves[gNumMoves].h=theMove.h;
  58.     gMoves[gNumMoves].v=theMove.v;
  59.     gNumMoves++;
  60.     
  61.     return TRUE;
  62. }
  63.  
  64. Boolean UndoOneMove(WindowDataHandle theData)
  65. {
  66.     Point            lastMove;
  67.     
  68.     if (gNumMoves==0)
  69.         return FALSE;
  70.     
  71.     lastMove=gMoves[--gNumMoves];
  72.     FramePosition(gCurrentRow, gCurrentColumn, FALSE);
  73.     gCurrentRow=lastMove.v;
  74.     gCurrentColumn=lastMove.h;
  75.     FramePosition(gCurrentRow, gCurrentColumn, TRUE);
  76.     
  77.     if (Board[gCurrentRow][gCurrentColumn]==0)
  78.         return FALSE;
  79.     
  80.     Board[gCurrentRow][gCurrentColumn]=0;
  81.     DrawOnePosition(gCurrentRow, gCurrentColumn, Board[gCurrentRow][gCurrentColumn], FALSE);
  82.     
  83.     (**theData).offscreenNeedsUpdate=TRUE;
  84.     
  85.     return TRUE;
  86. }
  87.  
  88.  
  89. void FramePosition(short theRow, short theColumn, Boolean isHighlighted)
  90. {
  91.     Rect            theRect;
  92.     
  93.     theRect.left=theColumn*38+2;
  94.     theRect.right=theRect.left+36;
  95.     theRect.top=theRow*38+2;
  96.     theRect.bottom=theRect.top+36;
  97.     InsetRect(&theRect, -1, -1);
  98.     if (!isHighlighted)
  99.         ForeColor(whiteColor);
  100.     FrameRect(&theRect);
  101.     ForeColor(blackColor);
  102. }
  103.  
  104. void DrawOnePosition(short theRow, short theColumn, short theValue, Boolean isHighlighted)
  105. {
  106.     Rect            tempRect;
  107.     
  108.     tempRect.top=theRow*38+2;
  109.     tempRect.bottom=tempRect.top+36;
  110.     tempRect.left=theColumn*38+2;
  111.     tempRect.right=tempRect.left+36;
  112.     InsetRect(&tempRect, 2, 2);
  113.     if (theValue==0)
  114.     {
  115.         EraseRect(&tempRect);
  116.     }
  117.     else
  118.     {
  119.         if (gHasColorQD)
  120.             PlotCIcon(&tempRect, gTheCIcon[theValue-1]);
  121.         else
  122.             PlotIcon(&tempRect, gTheIcon[theValue-1]);
  123.     }
  124.     if (isHighlighted)
  125.     {
  126.         InvertRect(&tempRect);
  127.     }
  128. }
  129.